#ifndef __MEDIACHANNEL_H__
#define __MEDIACHANNEL_H__

#include "SocketTcpClient.h"
#include "MyThread.h"
#include "ListPtr.h"
#include "Lock.h"
#include "define.h"

class CManager;
class CMediaChannel : public CMyThread
	,IOTcpClientNotify
{
public:
	CMediaChannel(CManager *pMan);
	~CMediaChannel(void);

	bool Start(void);
	void Stop(void);

	int SendDataToServer(int nCmd, const char *pData, int nDataLen);
protected:
	virtual void ThreadProcMain(void);
	virtual void OnRecvTcpServerDataNotify(const int nCmd, const int nPacketNum, const int nSendId, const char *szBuf, int nLen);
	virtual void OnDisConnTcpServerNotify(const int nType);

private:
	void HandleRecvData(void);
	void HandleSendData(void);

	int ConnectServer(void);

	int SendData(int nCmd, const char *pData, int nDataLen);
	void ClearRecvData(RecvDataInfo *pRecvData);

	bool SendChannelDeclare(void);
	bool SendHeartbetMsg(void);

	void HandleChannelDeclareRsp(RecvDataInfo *pRecvData);
	void HandleWbData(RecvDataInfo *pRecvData);

	void HandleWbFile(RecvDataInfo *pRecvData);
	void HandleWBFileStart(RecvDataInfo *pRecvData);
	void HandleWBFileEnd(RecvDataInfo *pRecvData);

	void HandleScreenBroadcastData(RecvDataInfo *pRecvData);

	int SendFileData(const char *pData, int nDataLen);
	int SendFileEnd(void);
private:
	CSocketTcpClient	*m_pClient;
	CManager			*m_pMan;

	bool				m_bExit;
	bool				m_bConnect;

	bool				m_bValid;
	bool				m_bFirstConnect;

	unsigned short		m_usPacketNum;

	unsigned long		m_ulLastConnectTime;
	unsigned long		m_ulLastSendTime;

	ListPtr				m_lstRecvData;
	CLock				m_lockRecvData;

	ListPtr				m_lstSendData;
	CLock				m_lockSendData;

	FILE				*m_pSaveFile;
	bool				m_bSaveVaild;
};

#endif
